//连接数据库，自己所写（非模板生成）
var mysql      = require('mysql');
var connection = mysql.createConnection({
  host     : 'localhost',
  user     : 'root',
  password : 'root',
  database : 'mmstore'
});
 
//连接模块暴露出去
module.exports = connection;

//在mysql中写入，创建数据库
/*
  //创建新的数据库
  create database mmstore;

  //打开新创建的数据库
  use mmstore;

  //创建表users
  create table users(
    id int primary key auto_increment,
    username varchar(30)  ,
    password varchar(30),
    sex varchar(10),
    introduction varchar(600)
  );

  //插入表数据
  insert into users(username,password,sex,introduction) values ('admin','123456','女','李嘉');
  insert into users(username,password,sex,introduction) values ('admin1','123456','男','梁山伯');
  insert into users(username,password,sex,introduction) values ('张老哥','123456','女','我是佛山十三姨');
  insert into users(username,password,sex,introduction) values ('黄飞鸿','123456','男','佛山无影脚');
  insert into users(username,password,sex,introduction) values ('马戈列特','123456','女','真好看');
  insert into users(username,password,sex,introduction) values ('娜美','123456','女','小贼猫');


  //创建表relatedProducts（周边商品表）
  create table relatedProducts(
    id int primary key auto_increment,
    type varchar(30),
    name varchar(40),
    describes varchar(400),
    username varchar(30),
  );
//创建评论表
  create table comments(
    id int primary key auto_increment,
    content varchar(300),
    whichProducts int,
    author varchar(30)
  );
  insert into comments(content,whichProducts,author) values ('假假假假假的嘉嘉加加家',1,'admin');
  insert into comments(content,whichProducts,author) values ('多少钱呀，邮费可以免费吗',1,'admin');
  
  //创建收藏表
  create table collected (
    uid int not null,
    pid int not null,
    primary key(uid,pid)
  );
  //alter table collected add constraint pk_collect primary key(uid,pid);
  alter table collected add constraint fk_user foreign key(uid) references users(id);
  alter table collected add constraint fk_product foreign key(pid) references relatedProducts(id);

  insert into collected values(1,1);
  insert into collected values(2,3);
  insert into collected values(1,2);
  insert into collected values(1,3);
  insert into collected values(1,4);
  insert into collected values(2,1);
  insert into collected values(3,1);
  insert into collected values(4,1);
  insert into collected values(5,1);
  insert into collected values(6,1);

  //查询 收藏id为1的商品 的用户
  select users.* from users left join collected on users.id = collected.uid where collected.pid = 1;
  
  //查询 id为1的用户 所收藏的商品
  select relatedProducts.* from relatedProducts left join collected on relatedProducts.id = collected.pid where collected.uid = 1;
  //更新用户数据
  update  users set username = ''  WHERE id ='';
  
  //创建短评表
  create table articles (
    id int primary key auto_increment,
    title varchar(40) not null,
    type varchar(20) not null,
    author varchar(20) not null,
    content varchar(300) not null,
    liked int not null,
    likedFrom varchar(30) 
  );
  insert into articles(title,type,author,content,liked) values ('《蓝色情人节》','movieWorld','admin','<p>Dean年轻时做搬运工，帮退伍老海军搬家时，他在那间窄窄的老年公寓里耐心地一一摆好老人的物件，并一一告诉老人物件的摆位。老人很感动，我也很感动。Dean是那种有爱的文艺青年，用心在感受生活。但文艺青年过婚姻生活往往是失败的。现世婚姻中衡量你是否幸福，不在于你的心多有爱，而是别的。</p>',0);
  insert into articles(title,type,author,content,liked) values ('《我的天才女友 第二季》','movieWorld','娜美','<p>莉拉被家暴了 只有莱农听到她的遭遇后愤怒流泪。阿方索说是莉拉不听话才被打的 莱农立即反问他 你也会对爱的人这样吗？/莱农问 为什么所有人都知道你回来了而我不知道 莉拉说 因为别人我不在乎 但我在乎你</p>',0);


  */